#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: title08查找充电设备组合.py 
@version:
@time: 2023/06/01 
"""


def solve_method(n, p, p_max):
    dp = [[0] * (p_max + 1) for _ in range(n + 1)]

    for i in range(1, n + 1):
        print(dp)
        for j in range(1, p_max + 1):
            if p[i - 1] > j:
                dp[i][j] = dp[i - 1][j]
            else:
                dp[i][j] = max(
                    dp[i - 1][j],
                    p[i - 1] + dp[i - 1][j - p[i - 1]]
                )
    return dp[n][p_max]


if __name__ == "__main__":
    n = int(input())
    p = [int(x) for x in input().split()]
    p_max = int(input())
    print(solve_method(n, p, p_max))
